package com.sky.service.impl.admin;

import com.sky.result.Result;
import com.sky.service.admin.UnloadService;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@Slf4j
@Service
public class UnloadServiceImpl implements UnloadService {
    @Autowired
    private AliOssUtil aliOssUtil;

    @Override
    public Result<String> unload(MultipartFile file) throws IOException {
        String[] split = file.getOriginalFilename().split("/.");
        String exname =   split[split.length - 1] + UUID.randomUUID().toString();
        String uploadUrl = aliOssUtil.upload(file.getBytes(), exname);

        return Result.success(uploadUrl);

    }
}
